#include <stm32f10x.h>
#include <message.h>

unsigned int BuildMessageU32(unsigned char receiverID, unsigned char senderID, unsigned char addressOpt, unsigned int content)
{
        unsigned int msg;

    msg = content & 0xFFFF;
        msg += (unsigned char)(addressOpt & 0xFF) << 16;
    msg += (unsigned char)(senderID & 0x0F) << 24;
        msg += (unsigned char)(receiverID & 0x0F)<< 28;

        return msg;
}

unsigned int ParseMsgSender(unsigned int msg)
{
        return (msg >> 24) & 0x0F;
}

unsigned int ParseMsgReceiver(unsigned int msg)
{
        return (msg >> 28) & 0x0F;
}

unsigned int ParseMsgAdrOpt(unsigned int msg)
{
        return (msg >> 16) & 0xFF;
}

unsigned int ParseMsgContent(unsigned int msg)
{
        return msg & 0xFFFF;
}

void DebugPrt(char* pStr) { }

void DebugOutMsg(u32 msgRx)
{
    u32 /*msgReceiver, msgSender,*/ msgAdrOpt, msgContent;

//    msgReceiver = ParseMsgReceiver(msgRx);
//    msgSender = ParseMsgSender(msgRx);
    msgAdrOpt = ParseMsgAdrOpt(msgRx);
    msgContent = ParseMsgContent(msgRx);

    if(msgAdrOpt > 0) return ;

    switch(msgContent)
    {
        case MSG_BLANK:                                DebugPrt("MSG_BLANK"); break;
        case MSG_SYS_PROBE:                            DebugPrt("MSG_SYS_PROBE"); break;
        case MSG_SYS_EMERGENCY:                        DebugPrt("MSG_SYS_EMERGENCY"); break;
        case MSG_LOCAL_TIMEOUT:                        DebugPrt("MSG_LOCAL_TIMEOUT"); break;
        case MSG_LINEIN_OVERSHORT_CMD:                 DebugPrt("MSG_LINEIN_OVERSHORT_CMD"); break;
        case MSG_LINEIN_OVERLENGTH_CMD:                DebugPrt("MSG_LINEIN_OVERLENGTH_CMD"); break;

        case MSG_LINEIN_FEED_ALIGN:                    DebugPrt("MSG_LINEIN_FEED_ALIGN"); break;
        case MSG_LINEIN_ANS_FEED_ALIGN_OK:             DebugPrt("MSG_LINEIN_ANS_FEED_ALIGN_OK"); break;
        case MSG_LINEIN_FEED_LINE:                     DebugPrt("MSG_LINEIN_FEED_LINE"); break;
        case MSG_LINEIN_ANS_FEED_LINE_OK:              DebugPrt("MSG_LINEIN_ANS_FEED_LINE_OK"); break;

        case MSG_STRIPLINE_HOMING:                     DebugPrt("MSG_STRIPLINE_HOMING"); break;
        case MSG_STRIPLINE_HOMEOVER:                   DebugPrt("MSG_STRIPLINE_HOMEOVER"); break;
        case MSG_STRIPLINE_STRIPPER_SEAT:              DebugPrt("MSG_STRIPLINE_STRIPPER_SEAT"); break;
        case MSG_STRIPLINE_ANS_STRIPPER_SEAT_OK:       DebugPrt("MSG_STRIPLINE_ANS_STRIPPER_SEAT_OK"); break;
        case MSG_STRIPLINE_CMD_STRIPPER_EX:            DebugPrt("MSG_STRIPLINE_CMD_STRIPPER_EX"); break;
        case MSG_STRIPLINE_ANS_STRIPPER_EX_OK:         DebugPrt("MSG_STRIPLINE_ANS_STRIPPER_EX_OK"); break;

        case MSG_OPERATION_1_HOMING:                   DebugPrt("MSG_OPERATION_1_HOMING"); break;
        case MSG_OPERATION_2_HOMING:                   DebugPrt("MSG_OPERATION_2_HOMING"); break;
        case MSG_OPERATION_3_HOMING:                   DebugPrt("MSG_OPERATION_3_HOMING"); break;
        case MSG_OPERATION_TOUCHSENSOR_1:              DebugPrt("MSG_OPERATION_TOUCHSENSOR_1"); break;
        case MSG_OPERATION_TOUCHSENSOR_2:              DebugPrt("MSG_OPERATION_TOUCHSENSOR_2"); break;
        case MSG_OPERATION_TOUCHSENSOR_3:              DebugPrt("MSG_OPERATION_TOUCHSENSOR_3"); break;
        case MSG_OPERATION_ARRIVED_1:                  DebugPrt("MSG_OPERATION_ARRIVED_1"); break;
        case MSG_OPERATION_ARRIVED_2:                  DebugPrt("MSG_OPERATION_ARRIVED_2"); break;
        case MSG_OPERATION_ARRIVED_3:                  DebugPrt("MSG_OPERATION_ARRIVED_3"); break;
        case MSG_OPERATION_CMD_RUN100:                 DebugPrt("MSG_OPERATION_CMD_RUN100"); break;

        case MSG_EVENT_TRIG_EXTI4_F:                   DebugPrt("MSG_EVENT_TRIG_EXTI4_F"); break;
        case MSG_EVENT_TRIG_EXTI4_R:                   DebugPrt("MSG_EVENT_TRIG_EXTI4_R"); break;

        case MSG_DISK_AT_LOAD:                         DebugPrt("MSG_DISK_AT_LOAD"); break;
        case MSG_DISK_AT_PIN:                          DebugPrt("MSG_DISK_AT_PIN"); break;
        case MSG_DISK_AT_SOLDERA:                      DebugPrt("MSG_DISK_AT_SOLDERA"); break;
        case MSG_DISK_AT_SOLDERB:                      DebugPrt("MSG_DISK_AT_SOLDERB"); break;
        case MSG_DISK_AT_PUNCH:                        DebugPrt("MSG_DISK_AT_PUNCH"); break;
        case MSG_DISK_AT_UNLOAD:                       DebugPrt("MSG_DISK_AT_UNLOAD"); break;

        case MSG_CA_SELFTEST:                          DebugPrt("MSG_CA_SELFTEST"); break;
        case MSG_CARRIER_SELFTEST_U1:                  DebugPrt("MSG_CARRIER_SELFTEST_U1"); break;
        case MSG_CARRIER_SELFTEST_U2:                  DebugPrt("MSG_CARRIER_SELFTEST_U2"); break;
        case MSG_CARRIER_SELFTEST_U3:                  DebugPrt("MSG_CARRIER_SELFTEST_U3"); break;
        case MSG_CARRIER_SELFTEST_U4:                  DebugPrt("MSG_CARRIER_SELFTEST_U4"); break;
        case MSG_CARRIER_SELFTEST_U5:                  DebugPrt("MSG_CARRIER_SELFTEST_U5"); break;
        case MSG_CARRIER_SELFTEST_U6:                  DebugPrt("MSG_CARRIER_SELFTEST_U6"); break;

        case MSG_CA_SELFTEST_OK:                       DebugPrt("MSG_CA_SELFTEST_OK"); break;
        case MSG_CA_SELFTEST_FAIL:                     DebugPrt("MSG_CA_SELFTEST_FAIL"); break;
        case MSG_CARRIER_SELFTEST_U1_OK:               DebugPrt("MSG_CARRIER_SELFTEST_U1_OK"); break;
        case MSG_CARRIER_SELFTEST_U2_OK:               DebugPrt("MSG_CARRIER_SELFTEST_U2_OK"); break;
        case MSG_CARRIER_SELFTEST_U3_OK:               DebugPrt("MSG_CARRIER_SELFTEST_U3_OK"); break;
        case MSG_CARRIER_SELFTEST_U4_OK:               DebugPrt("MSG_CARRIER_SELFTEST_U4_OK"); break;
        case MSG_CARRIER_SELFTEST_U5_OK:               DebugPrt("MSG_CARRIER_SELFTEST_U5_OK"); break;
        case MSG_CARRIER_SELFTEST_U6_OK:               DebugPrt("MSG_CARRIER_SELFTEST_U6_OK"); break;

        case MSG_POSE_A:                               DebugPrt("MSG_POSE_A"); break;
        case MSG_POSE_A_OK:                            DebugPrt("MSG_POSE_A_OK"); break;
        case MSG_POSE_B:                               DebugPrt("MSG_POSE_B"); break;
        case MSG_POSE_B_OK:                            DebugPrt("MSG_POSE_B_OK"); break;
        case MSG_POSE_C:                               DebugPrt("MSG_POSE_C"); break;
        case MSG_POSE_C_OK:                            DebugPrt("MSG_POSE_C_OK"); break;

        case MSG_CA_FREE:                              DebugPrt("MSG_CA_FREE"); break;
        case MSG_UL_UNLOAD:                            DebugPrt("MSG_UL_UNLOAD"); break;

        case MSG_START_REQ:                            DebugPrt("MSG_START_REQ"); break;
        case MSG_START_REQ_CFM:                        DebugPrt("MSG_START_REQ_CFM"); break;
        case MSG_CA_WIRE_FINGER_FREE:                  DebugPrt("MSG_CA_WIRE_FINGER_FREE"); break;
        case MSG_CA_WIRE_FINGER_FREE_OK:               DebugPrt("MSG_CA_WIRE_FINGER_FREE_OK"); break;

        case MSG_LOAD_LEAD:                            DebugPrt("MSG_LOAD_LEAD"); break;
        case MSG_LOAD_LEAD_OK:                         DebugPrt("MSG_LOAD_LEAD_OK"); break;
        case MSG_LOAD_FEED_MAN:                        DebugPrt("MSG_LOAD_FEED_MAN"); break;
        case MSG_LOAD_FEED_MAN_OK:                     DebugPrt("MSG_LOAD_FEED_MAN_OK"); break;

        case MSG_LOAD_FEED_ALIGN:                      DebugPrt("MSG_LOAD_FEED_ALIGN"); break;
        case MSG_LOAD_FEED_ALIGN_OK:                   DebugPrt("MSG_LOAD_FEED_ALIGN_OK"); break;
        case MSG_CA_LOCK_WIRE:                         DebugPrt("MSG_CA_LOCK_WIRE"); break;
        case MSG_CA_LOCK_WIRE_OK:                      DebugPrt("MSG_CA_LOCK_WIRE_OK"); break;
        case MSG_LOAD_FEED_LENGTH:                     DebugPrt("MSG_LOAD_FEED_LENGTH"); break;
        case MSG_LOAD_FEED_LENGTH_OK:                  DebugPrt("MSG_LOAD_FEED_LENGTH_OK"); break;
        case MSG_CA_HEIGHT_STRIP:                      DebugPrt("MSG_CA_HEIGHT_STRIP"); break;
        case MSG_CA_HEIGHT_STRIP_OK:                   DebugPrt("MSG_CA_HEIGHT_STRIP_OK"); break;
        case MSG_STRIP:                                DebugPrt("MSG_STRIP"); break;
        case MSG_STRIP_OK:                             DebugPrt("MSG_STRIP_OK"); break;

        case MSG_PIN_FEED:                            DebugPrt("MSG_PIN_FEED"); break;
        case MSG_PIN_FEED_OK:                         DebugPrt("MSG_PIN_FEED_OK"); break;
        case MSG_CA_FINGER_LOCK:                      DebugPrt("MSG_CA_FINGER_LOCK"); break;
        case MSG_CA_FINGER_LOCK_OK:                   DebugPrt("MSG_CA_FINGER_LOCK_OK"); break;
        case MSG_PIN_NEXT:                            DebugPrt("MSG_PIN_NEXT"); break;
        case MSG_PIN_APART:                           DebugPrt("MSG_PIN_APART"); break;

        case MSG_SOLDERA_PIN_TO_POSE_A:               DebugPrt("MSG_SOLDERA_PIN_TO_POSE_A"); break;
        case MSG_SOLDERA_PIN_TO_POSE_A_OK:            DebugPrt("MSG_SOLDERA_PIN_TO_POSE_A_OK"); break;
        case MSG_SOLDERA_WIRE_TO_POSE_A:              DebugPrt("MSG_SOLDERA_WIRE_TO_POSE_A"); break;
        case MSG_SOLDERA_WIRE_TO_POSE_A_OK:           DebugPrt("MSG_SOLDERA_WIRE_TO_POSE_A_OK"); break;
        case MSG_SOLDERA_EX:                          DebugPrt("MSG_SOLDERA_EX"); break;
        case MSG_SOLDERA_EX_OK:                       DebugPrt("MSG_SOLDERA_EX_OK"); break;

        case MSG_SOLDERB_PIN_TO_POSE_B:               DebugPrt("MSG_SOLDERB_PIN_TO_POSE_B"); break;
        case MSG_SOLDERB_PIN_TO_POSE_B_OK:            DebugPrt("MSG_SOLDERB_PIN_TO_POSE_B_OK"); break;
        case MSG_SOLDERB_WIRE_TO_POSE_B:              DebugPrt("MSG_SOLDERB_WIRE_TO_POSE_B"); break;
        case MSG_SOLDERB_WIRE_TO_POSE_B_OK:           DebugPrt("MSG_SOLDERB_WIRE_TO_POSE_B_OK"); break;
        case MSG_SOLDERB_EX:                          DebugPrt("MSG_SOLDERB_EX"); break;
        case MSG_SOLDERB_EX_OK:                       DebugPrt("MSG_SOLDERB_EX_OK"); break;

        case MSG_PUNCH_PIN_TO_POSE_C:                 DebugPrt("MSG_PUNCH_PIN_TO_POSE_C"); break;
        case MSG_PUNCH_PIN_TO_POSE_C_OK:              DebugPrt("MSG_PUNCH_PIN_TO_POSE_C_OK"); break;
        case MSG_PUNCH_WIRE_TO_POSE_C:                DebugPrt("MSG_PUNCH_WIRE_TO_POSE_C"); break;
        case MSG_PUNCH_WIRE_TO_POSE_C_OK:             DebugPrt("MSG_PUNCH_WIRE_TO_POSE_C_OK"); break;
        case MSG_PUNCH_EX:                            DebugPrt("MSG_PUNCH_EX"); break;
        case MSG_PUNCH_EX_OK:                         DebugPrt("MSG_PUNCH_EX_OK"); break;
        case MSG_PUNCH_FINGER_OPEN_VOID:              DebugPrt("MSG_PUNCH_FINGER_OPEN_VOID"); break;
        case MSG_PUNCH_FINGER_OPEN_VOID_OK:           DebugPrt("MSG_PUNCH_FINGER_OPEN_VOID_OK"); break;

        case MSG_ULD_TO_UNLOAD:                       DebugPrt("MSG_ULD_TO_UNLOAD"); break;
        case MSG_ULD_TO_UNLOAD_OK:                    DebugPrt("MSG_ULD_TO_UNLOAD_OK"); break;

        case MSG_ULD_WIRE_OPEN:                       DebugPrt("MSG_ULD_WIRE_OPEN"); break;
        case MSG_ULD_WIRE_OPEN_OK:                    DebugPrt("MSG_ULD_WIRE_OPEN_OK"); break;
        case MSG_ULD_EX:                              DebugPrt("MSG_ULD_EX"); break;
        case MSG_ULD_EX_OK:                           DebugPrt("MSG_ULD_EX_OK"); break;

        case MSG_LD_HEAD_LOWER:                       DebugPrt("MSG_LD_HEAD_LOWER"); break;
        case MSG_LD_HEAD_LIFT:                        DebugPrt("MSG_LD_HEAD_LIFT"); break;
        case MSG_LD_HEAD_CUT:                         DebugPrt("MSG_LD_HEAD_CUT"); break;
        case MSG_LD_HEAD_FEED:                        DebugPrt("MSG_LD_HEAD_FEED"); break;

        case MSG_IDXU_READY_ON_LOAD:                  DebugPrt("MSG_IDXU_READY_ON_LOAD"); break;
        case MSG_IDXU_READY_ON_PIN:                   DebugPrt("MSG_IDXU_READY_ON_PIN"); break;
        case MSG_IDXU_READY_ON_SLDA:                  DebugPrt("MSG_IDXU_READY_ON_SLDA"); break;
        case MSG_IDXU_READY_ON_SLDB:                  DebugPrt("MSG_IDXU_READY_ON_SLDB"); break;
        case MSG_IDXU_READY_ON_PUNCH:                 DebugPrt("MSG_IDXU_READY_ON_PUNCH"); break;
        case MSG_IDXU_READY_ON_UNLOAD:                DebugPrt("MSG_IDXU_READY_ON_UNLOAD"); break;

        case MSG_IDXU_SHIFT:                          DebugPrt("MSG_IDXU_SHIFT"); break;
        case MSG_IDXU_STARTWORK:                      DebugPrt("MSG_IDXU_STARTWORK"); break;
        case MSG_INDEXUNIT_INDEXSENOR_SET:            DebugPrt("MSG_INDEXUNIT_INDEXSENOR_SET"); break;
        case MSG_INDEXUNIT_CHECKSENSOR_SET:           DebugPrt("MSG_INDEXUNIT_CHECKSENSOR_SET"); break;
        case MSG_INDEXUNIT_BACKPST_SET:               DebugPrt("MSG_INDEXUNIT_BACKPST_SET"); break;
        case MSG_INDEXUNIT_EMERGENCY:                 DebugPrt("MSG_INDEXUNIT_EMERGENCY"); break;
        case MSG_INDEXUNIT_TOUCHZERO:                 DebugPrt("MSG_INDEXUNIT_TOUCHZERO"); break;
        case MSG_INDEXUNIT_STOP_ST1:                  DebugPrt("MSG_INDEXUNIT_STOP_ST1"); break;
        case MSG_INDEXUNIT_STOP_ST2:                  DebugPrt("MSG_INDEXUNIT_STOP_ST2"); break;
        case MSG_INDEXUNIT_STOP_ST3:                  DebugPrt("MSG_INDEXUNIT_STOP_ST3"); break;
        case MSG_INDEXUNIT_STOP_ST4:                  DebugPrt("MSG_INDEXUNIT_STOP_ST4"); break;
        case MSG_INDEXUNIT_STOP_ST5:                  DebugPrt("MSG_INDEXUNIT_STOP_ST5"); break;
        case MSG_INDEXUNIT_STOP_ST6:                  DebugPrt("MSG_INDEXUNIT_STOP_ST6"); break;

        case MSG_UNIT_PROCESS:                        DebugPrt("MSG_UNIT_PROCESS"); break;
        case MSG_UNIT_ALLTEST:                        DebugPrt("MSG_UNIT_ALLTEST"); break;

        case MSG_SLDA_SELFTEST:                       DebugPrt("MSG_SLDA_SELFTEST"); break;
        case MSG_SLDB_SELFTEST:                       DebugPrt("MSG_SLDB_SELFTEST"); break;
        case MSG_PIN_SELFTEST:                        DebugPrt("MSG_PIN_SELFTEST"); break;
        case MSG_IDXU_SELFTEST:                       DebugPrt("MSG_IDXU_SELFTEST"); break;
        case MSG_LDULD_SELFTEST:                      DebugPrt("MSG_LDULD_SELFTEST"); break;
        case MSG_PUNC_SELFTEST:                       DebugPrt("MSG_PUNC_SELFTEST"); break;

        case MSG_SLDA_SELFTEST_OK:                    DebugPrt("MSG_SLDA_SELFTEST_OK"); break;
        case MSG_SLDB_SELFTEST_OK:                    DebugPrt("MSG_SLDB_SELFTEST_OK"); break;
        case MSG_PIN_SELFTEST_OK:                     DebugPrt("MSG_PIN_SELFTEST_OK"); break;
        case MSG_IDXU_SELFTEST_OK:                    DebugPrt("MSG_IDXU_SELFTEST_OK"); break;
        case MSG_LDULD_SELFTEST_OK:                   DebugPrt("MSG_LDULD_SELFTEST_OK"); break;
        case MSG_PUNC_SELFTEST_OK:                    DebugPrt("MSG_PUNC_SELFTEST_OK"); break;

        case MSG_UNIT_ALLTEST_OK:                     DebugPrt("MSG_UNIT_ALLTEST_OK"); break;

        case MSG_SYS_ACK:                             DebugPrt("MSG_SYS_ACK"); break;
        case MSG_SYS_RESET:                           DebugPrt("MSG_SYS_RESET"); break;

        case MSG_SLD_ONCE:                            DebugPrt("MSG_SLD_ONCE"); break;

        case MSG_NEW:                                 DebugPrt("MSG_NEW"); break;
        default:
            DebugPrt("...");
    }
}


